package es.app.util;
import java.io.Serializable;
import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public abstract class GenericDAOHibernate<T extends Serializable, E> extends
		HibernateDaoSupport implements GenericDAO<T, E> {
	
	protected HibernateTemplate template;
	
	protected void init(){
		template = getHibernateTemplate();
	}
	
	public E create(T object) throws RuntimeException {
		try {
			return (E) template.save(object);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}


	public void update(T transientObject) throws RuntimeException {
		try {
			template.update(transientObject);
		} catch (Exception e) {
			
			throw new RuntimeException(e);
		}
	}

	public void delete(T persistentObject) throws RuntimeException {
		try {
			template.delete(persistentObject);
		} catch (RuntimeException e) {
			throw new RuntimeException(e);
		}
	}
	
	public abstract List<T> findAll() throws RuntimeException;

	public abstract T findById(E id) throws RuntimeException;

}
